package com.onelap.bls.treadmillcalibration.activity.index;

import android.bluetooth.BluetoothDevice;
import android.support.annotation.Nullable;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.onelap.bls.treadmillcalibration.R;
import com.onelap.bls.treadmillcalibration.utils.ScanRecordUtil;

import java.util.List;
import java.util.logging.Logger;


public class DeviceListAdapter extends BaseQuickAdapter<DeviceBean, BaseViewHolder> {


    public DeviceListAdapter(@Nullable List<DeviceBean> data) {
        super(R.layout.item_device_list, data);

    }



    @Override
    protected void convert(BaseViewHolder helper, DeviceBean item) {
        helper.setText(R.id.tv_name, item.getDevice().getName());
        helper.setText(R.id.tv_address, item.getDevice().getAddress());
        helper.setText(R.id.tv_paired, item.getDevice().getBondState() == BluetoothDevice.BOND_BONDED ? "paired" : "");
        helper.setText(R.id.tv_rssi, item.getRssi() == 0 || item.getRssi() == -0 ? "" : "Rssi = " + String.valueOf(item.getRssi()));
        if (item.getBroadcastPacket() != null) {
            String usefulData = ScanRecordUtil.getStrScanRecord(item.getBroadcastPacket()).substring(86, 106);//4252 3d6400cdff003a9e
//                String serviceID1 = usefulData.substring(2);
//                    String serviceID = usefulData.substring(2, 4);
//                    if (serviceID.equals("52")) {
            String strVersion = usefulData.substring(4, 6);
            int intVersion = Integer.parseInt(strVersion, 16);
            String strPower = usefulData.substring(6, 8);
            int intPower = Integer.parseInt(strPower, 16);
         //   helper.setText(R.id.tv_temp, ScanRecordUtil.getStrScanRecord(item.getBroadcastPacket()).concat("=====================版本值=").concat(ScanRecordUtil.getVersion(item.getBroadcastPacket()).concat("；电量=").concat(ScanRecordUtil.getPower(item.getBroadcastPacket()))));
            helper.setText(R.id.tv_temp, ScanRecordUtil.getStrScanRecord(item.getBroadcastPacket()).concat("=====================版本值=").concat(String.valueOf(intVersion)).concat("；电量=").concat(String.valueOf(intPower)));
        }

        helper.setBackgroundColor(R.id.rl_root, item.isSelect() ? mContext.getResources().getColor(R.color.color5) : mContext.getResources().getColor(R.color.color4));
        helper.setTextColor(R.id.tv_name, item.isSelect() ? mContext.getResources().getColor(R.color.colorWhite) : mContext.getResources().getColor(R.color.BLS_black));
        helper.setTextColor(R.id.tv_address, item.isSelect() ? mContext.getResources().getColor(R.color.colorWhite) : mContext.getResources().getColor(R.color.color3));
        helper.setTextColor(R.id.tv_paired, item.isSelect() ? mContext.getResources().getColor(R.color.colorWhite) : mContext.getResources().getColor(R.color.color3));
        helper.setTextColor(R.id.tv_rssi, item.isSelect() ? mContext.getResources().getColor(R.color.colorWhite) : mContext.getResources().getColor(R.color.color3));
    }


}
